//
//  HBReadSettingManager.m
//  HeartBeat
//
//  Created by karong on 2023/9/12.
//

#import "HBReadSettingManager.h"
#import "HBReadSettingModel.h"

@implementation HBReadSettingManager
SingletonM
+ (NSDictionary *)defultAttFontDic {
    HBReadSettingModel * model = [[HBReadSettingManager shared]showModel];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.lineSpacing = model.lineSpacing;
    style.firstLineHeadIndent = model.firstLineHeadIndent;
    style.paragraphSpacingBefore = model.paragraphSpacingBefore;
    style.paragraphSpacing = model.paragraphSpacing;
    style.alignment = NSTextAlignmentLeft;
    style.allowsDefaultTighteningForTruncation = YES;
    return @{NSFontAttributeName: [UIFont systemFontOfSize:model.font],NSForegroundColorAttributeName:[UIColor colorFromHexRGB:model.colorStr], NSParagraphStyleAttributeName:style};
}

- (HBReadSettingModel *)showModel {
    return [HBReadSettingModel showData];
}

- (UIColor *)showSkinColor {
    HBReadSettingModel * model = [[HBReadSettingManager shared] showModel];
    if (model.night) {
        return UIColor.font_black_1A1A1A;
    }else{
        HBReadColor skinStyle = model.state;
        return [UIColor colorFromHexRGB:NovelReadBgColor[skinStyle]];
    }
    return [UIColor colorFromHexRGB:@"FFF9EB"];
}

- (void)saveModel:(HBReadSettingModel *)saveModel {
    [HBReadSettingModel saveData:saveModel];
}

- (void)setNightWithIfNight:(BOOL)ifNight {
    HBReadSettingModel * model = [[HBReadSettingManager shared] showModel];
    if(model.night != ifNight) {
        model.night = ifNight;
        NSString * color = @"666D73";
        if (!ifNight) {
            color = @"353535";
        }
        model.colorStr = color;
        [[HBReadSettingManager shared] saveModel:model];
    }
}

- (void)setFontSize:(NSInteger)fontSize {
    HBReadSettingModel * model = [[HBReadSettingManager shared] showModel];
    if (model.font != fontSize) {
        model.font = fontSize;
        [[HBReadSettingManager shared] saveModel:model];
    }
}

- (void)setLineSpacing:(NSInteger)lineSpac {
    HBReadSettingModel * model = [[HBReadSettingManager shared] showModel];
    if (model.lineSpacing != lineSpac) {
        model.lineSpacing = lineSpac;
        [[HBReadSettingManager shared] saveModel:model];
    }
}

- (void)setBrowseState:(HBBrowseType)state {
    HBReadSettingModel * model = [[HBReadSettingManager shared] showModel];
    if (model.browseState != state) {
        model.browseState = state;
        [[HBReadSettingManager shared] saveModel:model];
    }
}

- (void)setReadColorState:(HBReadColor)state {
    HBReadSettingModel * model = [[HBReadSettingManager shared] showModel];
    if (model.state != state) {
        model.state = state;
        [[HBReadSettingManager shared] saveModel:model];
    }
}
@end
